﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class NetUse
    {

        public static string[] GetNetDir(string SPATH)
        {
            try
            {
                Directory.GetFiles(SPATH);
            }
            catch
            {
                Process process = new Process();
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.Start();
                process.StandardInput.WriteLine("net use " + SPATH + " /delete");//删除已有的连接 避免单独占用
                process.StandardInput.WriteLine("net use " + SPATH + " foxconn@2008 /USER:ccib");
                process.StandardInput.WriteLine("exit");
            }
            return Directory.GetDirectories(SPATH);
        }

    }
}
